package com.flink.hbase.multithreaded;

import org.apache.hadoop.hbase.util.Bytes;

import java.io.Serializable;
import java.util.List;

/**
 * HBase Region 分配信息
 */
public class RegionAssignment implements Serializable {
    private final int taskIndex;
    private final List<RegionInfo> regions;
    
    public RegionAssignment(int taskIndex, List<RegionInfo> regions) {
        this.taskIndex = taskIndex;
        this.regions = regions;
    }
    
    public int getTaskIndex() {
        return taskIndex;
    }
    
    public List<RegionInfo> getRegions() {
        return regions;
    }
    
    public static class RegionInfo implements Serializable {
        private final String regionName;
        private final byte[] startKey;
        private final byte[] endKey;
        private final String serverName;
        
        public RegionInfo(String regionName, byte[] startKey, byte[] endKey, String serverName) {
            this.regionName = regionName;
            this.startKey = startKey;
            this.endKey = endKey;
            this.serverName = serverName;
        }
        
        public String getRegionName() {
            return regionName;
        }
        
        public byte[] getStartKey() {
            return startKey;
        }
        
        public byte[] getEndKey() {
            return endKey;
        }
        
        public String getServerName() {
            return serverName;
        }
        
        @Override
        public String toString() {
            return "RegionInfo{" +
                    "regionName='" + regionName + '\'' +
                    ", startKey=" + Bytes.toStringBinary(startKey) +
                    ", endKey=" + Bytes.toStringBinary(endKey) +
                    ", serverName='" + serverName + '\'' +
                    '}';
        }
    }
    
    @Override
    public String toString() {
        return "RegionAssignment{" +
                "taskIndex=" + taskIndex +
                ", regions=" + regions.size() +
                '}';
    }
} 